﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代垫操作</title>
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/Plugin/om-yj-container.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript" src="../Scripts/banBackSpace.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="../Scripts/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../Scripts/themes/icon.css">
    <script type="text/javascript">
        var detailPanel, listGrid, toolButtonBar, colData, searchPanel, defaultSort, defaultWhere, validatorForm, submitForm, currentUID, currentGIndex, modelDialog, showCDialog;
        var showSearchPanel, showDetialForm, controlBtn, oldRowData, detailForm, goOn = true, genRenderCheckbox, genRenderDateformat, comboxFeeTypeData=[];
        var actionRoot = "../handler/ajax.ashx?type=AjaxSystem";

        $(document).ready(function () {
            currentUID = art.dialog.data('currentUID');
            currentGIndex = art.dialog.data('Index');
            rowData = art.dialog.data('RowData');
            mode = art.dialog.data('Mode');
            detailForm = $('#viewForm');
            showToolBar(detailForm);
            $(":input", detailForm).change(function () { detailForm.data('changed', true); });
            validatorForm = $('#viewForm').validate({
                errorContainer: "#errorMessages",
                errorLabelContainer: "#errorMessages",
                wrapper: "span",
                errorClass: "omError",
                rules: {
                    DeclareNo: { required: true },
                    OrderNo: { required: true },
                    FeeType: { required: true },
                    Amount: { required: true,number: true },
                },
                messages: {
                    DeclareNo: { required: "报关单号不能为空" },
                    OrderNo: { required: "业务流水号不能为空" },
                    FeeType: { required: "费用项目不能为空" },
                    Amount: { required: "金额不能为空", number: "金额必须为数字" },
                }
            });
            //加载费用项目

            $.ajax({
                cache: false, async: false,
                url: '../Handler/combox.ashx?view=vBaseData',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载银行账号信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    comboxFeeTypeData = []
                    $.each(data, function (index, value) {
                        switch (value.Type) {
                            case '关税费用名称':
                                comboxFeeTypeData.push({ name: value.Name, code: value.Code, type: value.Type });
                                return true;
                            default:
                                return true;
                        }
                    })
                    $('#FeeType', detailForm).combobox({
                        data: comboxFeeTypeData,
                        valueField: 'name',
                        textField: 'name',
                    });
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.waiting("close");
                    $.omMessageBox.alert({
                        content: '发现错误<BR>：' + result.status
                    });
                }
            });
            $("#DeptName1", detailForm).attr("readonly", true);
            $("#DeptName2", detailForm).attr("readonly", true);
            $("#CustomerName", detailForm).attr("readonly", true);
            $("#DealinName", detailForm).attr("readonly", true);
            $("#OrderNo", detailForm).attr("readonly", true);
            showDetialForm("数据明细", rowData);
            switch (mode) {
                case 'new':
                    $('#UID', detailForm).val("0");
                    $("input[type=text]", detailPanel).each(function (index, element) {
                        $(this).val("");
                        if (index == 1) $(this).focus();
                    })
                    $("#Amount", detailForm).val("0");
                    $('span#button-saveadd', detailForm).omButton('enable');
                    break;
                case 'update':
                    $('#OrderNo', detailForm).attr("readonly", true);
                    $('#DeclareNo', detailForm).attr("readonly", true);
                    $('span#button-saveadd', detailForm).omButton('disable');
                    $("#Amount", detailForm).focus();
                    break;
            };
            $("#DeclareNo").change(function () {
                if ($(this).val().length > 0) {
                    $.ajax({
                        cache: false, async: false,
                        url: '../handler/ajax.ashx?type=AjaxSystem&method=CheckDeclareOrderNo',
                        dataType: 'json', type: 'post',
                        data: { USERID: currentUID, ORDERNO: $(this).val() },
                        beforeSend: function () {
                            $.omMessageBox.waiting({
                                title: '请等待',
                                content: '服务器正在验证流水号信息,请稍后...'
                            });
                        },
                        complete: function () { $.omMessageBox.waiting("close"); },
                        success: function (data) {
                            if (data.IsError) {
                                $(this).val("");
                                $("#DeptName1").val("");
                                $("#DeptName2").val("");
                                $("#CustomerName").val("");
                                $("#DealinName").val("");
                                $("#OrderNo").val("");
                                $("#FeeType").focus();
                            }
                            else {
                                var tempDept = JSON.parse(data.Data);
                                $("#DeptName1").val(tempDept[0].DeptName1);
                                $("#DeptName2").val(tempDept[0].DeptName2);
                                $("#CustomerName").val(tempDept[0].CustomerName);
                                $("#DealinName").val(tempDept[0].DealinName);
                                $("#OrderNo").val(tempDept[0].OrderNo);
                                $("#FeeType").focus();
                            }
                        },
                        error: function (result) {
                            $(this).val("");
                            $("#DeptName1").val("");
                            $("#DeptName2").val("");
                            $("#CustomerName").val("");
                            $("#DealinName").val("");
                            $("#OrderNo").val("");
                            $(this).focus();
                        }
                    })
                }
            });
        });

        showToolBar = function (form) {
            $('span#button-save', form).omButton({
                icons: { left: '../Content/Images/List/accept.png' }, width: 80,
                onClick: function () {
                    if (!detailForm.data('changed')) {
                        $.omMessageBox.alert({
                            type: 'warning',
                            title: '友情提醒',
                            content: '表单数据没有更改无需保存'
                        });
                    }
                    else {
                        if (validatorForm.form()) {
                            if (mode == 'update' && $("#UID").val() != "0") {
                                detailForm.attr("action", actionRoot + "&method=UpdateInstead");
                            }
                            else {
                                detailForm.attr("action", actionRoot + "&method=AddInstead");
                            }
                            submitForm(detailForm, function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        type: 'error',
                                        content: '发现错误<BR>：' + data.Message,
                                        onClose: function () {
                                            $("#OrderNo", detailForm).focus();
                                        }
                                    });
                                }
                                else {
                                    $.omMessageBox.alert({
                                        type: 'success',
                                        content: '代垫登记成功',
                                        onClose: function () {
                                            art.dialog.close();
                                        }
                                    })
                                }
                            });
                        }
                    }

                }
            });
            $('span#button-saveadd', form).omButton({
                icons: { left: '../Content/Images/List/ok.gif' }, width: 80,
                onClick: function () {
                    if (!detailForm.data('changed')) {
                        $.omMessageBox.alert({
                            type: 'warning',
                            title: '友情提醒',
                            content: '表单数据没有更改无需保存'
                        });
                    }
                    else {
                        if (validatorForm.form()) {
                            if (mode == 'update' && $("#UID").val() != "0") {
                                detailForm.attr("action", actionRoot + "&method=UpdateInstead");
                            }
                            else {
                                detailForm.attr("action", actionRoot + "&method=AddInstead");
                            }
                            submitForm(detailForm, function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        type: 'error',
                                        content: '发现错误<BR>：' + data.Message,
                                        onClose: function () {
                                            $("#OrderNo", detailForm).focus();
                                        }
                                    });
                                }
                                else {
                                    $.omMessageBox.alert({
                                        type: 'success',
                                        content: '代垫登记成功',
                                        onClose: function () {
                                            $('#UID', detailForm).val("0");
                                            $("#Amount", detailForm).val("0");
                                            $("#Feetype", detailForm).focus();
                                            $('span#button-saveadd', detailForm).omButton('enable');
                                        }
                                    })
                                }
                            });
                        }
                    }

                }
            });
            $('span#button-cancel', form).omButton({
                icons: { left: '../Content/Images/List/cross.png' }, width: 80,
                onClick: function () {
                    art.dialog.close();
                }
            });
        }

        showDetialForm = function (title, rowData) {
            if (detailPanel) {
                $("input[type=text]", detailPanel).val("");
                detailPanel.omPanel("open");
            }
            else {
                detailPanel = $('#detail-form').omPanel({
                    width: 'fit',
                    title: "<span style='color:#15428B;font-weight: bold;padding:6px;'>" + title + "</span>",
                    collapsed: false,
                    collapsible: false,
                    closable: false
                });
            }
            validatorForm.resetForm();
            rowData = rowData || {};
            $.each(rowData, function (n, value) {
                if (n == 'PurchaseDate')
                    $("input[id='" + n + "']", detailPanel).val(value == null ? '' : new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd"));
                else {
                    if (n == 'FeeType') {
                        $('#' + n, detailForm).combobox("setValue",value);// .omCombo("value", value);
                    }
                    else {
                        $("input[id='" + n + "']", detailPanel).val(value);
                    }
                }
            })
        };

        submitForm = function (mainform, success, error) {
            if (!mainform)
                return false;
            else {
                mainform.ajaxSubmit({
                    type: "POST",
                    dataType: 'json',
                    success: success,
                    clearForm: false,
                    beforeSubmit: function (formData, jqForm, options) {
                        $(":checkbox,:radio", jqForm).each(function () {
                            if (!existInFormData(formData, this.name)) {
                                formData.push({ name: this.name, type: this.type, value: this.checked });
                            }
                        });
                        for (var i = 0, l = formData.length; i < l; i++) {
                            var o = formData[i];
                            if (o.type == "checkbox" || o.type == "radio") {
                                o.value = $("[name=" + o.name + "]", jqForm)[0].checked ? "true" : "false";
                            }
                        }
                    },
                    beforeSend: function (a, b, c) {
                        $.omMessageBox.waiting({
                            title: '正在保存数据中...',
                            content: '服务器正在处理请求......'
                        });
                    },
                    complete: function () {
                        $.omMessageBox.waiting("close")
                    },
                    error: function (result) {
                        $.omMessageBox.waiting("close")
                        $.omMessageBox.alert({
                            content: '发现错误<BR>：' + result.status
                        });
                    }
                });
            }
        }

        function existInFormData(formData, name) {
            for (var i = 0, l = formData.length; i < l; i++) {
                var o = formData[i];
                if (o.name == name) return true;
            }
            return false;
        }

    </script>
</head>
<body>
    <div id="detail-form">
        <form id="viewForm">
            <div id="errorMessages" class="error"></div>
            <table>
                <tr style="display:none;">
                    <td colspan="6">
                        <input name="UID" id="UID" value="0" tabindex="-1" />
                    </td>
                </tr>
                <tr>
                    <td align="right" style="width: 80px;color: red;">报关单号</td>
                    <td align="left" style="width: 170px">
                        <input type="text" class="input-text" name="DeclareNo" id="DeclareNo" value="" maxlength="9" 
                            style="border: 1px solid #A4BED4; height:20px;width: 118px;" /></td>
                    </td>
                    <td align="right" style="width: 80px; color: red;">业务流水</td>
                    <td align="left" style="width: 170px">
                        <input type="text" class="input-text" name="OrderNo" id="OrderNo" 
                            style="border: 1px solid #A4BED4; height:20px;width: 118px;" /></td>
                    <td align="right" style="width: 80px; ">客户名称</td>
                    <td align="left" style="width: 170px">
                        <input type="text" class="input-text" name="CustomerName" id="CustomerName" value="" 
                            style="border: 1px solid #A4BED4; height:20px;width: 118px;" /></td>
                    </td>
                    
                </tr>
                <tr>
                    <td align="right" style="width: 80px; ">一级部门</td>
                    <td align="left" style="width: 170px">
                        <input type="text" class="input-text" name="DeptName1" id="DeptName1" value="" 
                            style="border: 1px solid #A4BED4; height:20px;width: 118px;" /></td>
                    <td align="right" style="width: 80px;">二级部门</td>
                    <td align="left" style="width: 170px">
                        <input type="text" class="input-text" name="DeptName2" id="DeptName2" 
                            style="border: 1px solid #A4BED4; height:20px;width: 118px;" /></td>
                    <td align="right" style="width: 80px;">经营单位</td>
                    <td align="left" style="width: 170px" >
                        <input type="text" class="input-text" name="DealinName" id="DealinName" 
                            style="border: 1px solid #A4BED4; height:20px;width: 118px;" /></td>
                </tr>
                <tr>
                     
                    <td align="right" style="width: 80px; color: red;">费用项目</td>
                    <td align="left" style="width: 170px">
                        <input class="easyui-combobox" name="FeeType" id="FeeType" tabindex="3" style="height:20px;width: 120px;" />
                    </td>
                    <td align="right" style="width: 80px; margin-left: 10px; color: red;">金额</td>
                    <td align="left" style="width: 170px">
                        <input type="text" class="easyui-numberbox" name="Amount" id="Amount" value="" 
                             style="border: 1px solid #A4BED4; height:20px;width: 118px;" /></td>
                   </td>
                </tr>
                <tr>
                    <td colspan="6" align="center">
                        <span id="button-saveadd">保存新增</span>
                        <span id="button-save">保存</span>
                        <span id="button-cancel">取消</span>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>
